package org.freemarker.core.dao.impl;

import javax.persistence.NoResultException;
import javax.persistence.Query;

import org.freemarker.core.dao.UserDao;
import org.freemarker.core.model.User;
import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl extends EntityJpaDaoImpl<User> implements UserDao {

	public UserDaoImpl() {
		setClazz(User.class);
	}

	@Override
	public User getUserByUsername(String username) {
		try {
			Query q = super.entityManager.createQuery("FROM " + clazz.getName()
					+ " WHERE username = '" + username + "'");
			User result = (User) q.getSingleResult();
			return result;
		} catch (NoResultException e) {
			return null;
		}
	}

}
